package com.cqs.leetcode.bit;

/**
 * @author lixiaowen
 * @create 2019-12-21
 */
public class CountingBits338 {

    static class Solution {

        public int[] countBits(int num) {
            int[] result = new int[num];
            if (num <=0) return result;
            result[0] = 0;
            for (int i = 1; i < num; ++i){
                //i&i-1清除最低位的０
                //i => i&(i-1) 补一个１得来　
                result[i] = result[i&(i-1)] + 1;
            }
            return result;
        }
    }

}
